package io.huaguoguo;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import org.omg.CORBA.TIMEOUT;

import java.io.IOException;
import java.net.BindException;
import java.net.Socket;

import static cn.hutool.core.util.CharsetUtil.GBK;

/**
 * 描述：  <br>
 * CreateDate: 2021/11/24 <br>
 *
 * @author huaguoguo
 */
public class BIOClient {

    public static void main(String[] args) throws IOException {
        String ipAddress = "127.0.0.1";
        int port = 7777;
        int i = 1;
        for (;;) {
            try {
                Socket socket = new Socket(ipAddress, port);
                String randomString = "第" + i + "条消息：" +  RandomUtil.randomString(6);
                socket.getOutputStream().write(randomString.getBytes(GBK));
                socket.close();
                i++;
            } catch (BindException e) {

            }
        }
    }
}
